package com.qf.air.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author songfei
 * @Date 2021/11/5 21:29
 * @Version 1.0
 */
@Configuration     //<beans>
public class ElasticsearchConfig {

    @Value("${es.host}")
    private String host;
    @Value("${es.port}")
    private int port;
    @Bean   //<bean    id = 方法名  class = 方法返回值>
    public RestHighLevelClient restHighLevelClient(){
        HttpHost httpHost = new HttpHost(host,port);
        RestClientBuilder builder = RestClient.builder(httpHost);
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        //方法返回结果就是放到spring一级缓存中的结果
        return restHighLevelClient;
    }

}
